package generics.rawtype;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Favorites {
    private Map<Class<?>, Object> favorites =
            new HashMap<>();
    public <T> void putFavorite(Class<T> type, T instance){
        if (type == null) {
            throw new NullPointerException();
        }
        favorites.put(type, type.cast(instance));
    }
    public <T> T getFavorite(Class<T> type){
        return type.cast(favorites.get(type));
    }

    @Test
    public void test() {
        Favorites favorites = new Favorites();
        List<?> list= new ArrayList<>();

        favorites.putFavorite(List.class, list);
        final List favorite = favorites.getFavorite(List.class);
//        String s  = (String) favorite.get(1);
//        Integer i = (Integer) favorite.get(0);
    }
}
